<?php
/**
 * include files & define sth & waiting for run.
 */
#

define('ROOT_PATH',		dirname(__FILE__));

//define('MOD_CLI',		PHP_SAPI=='cli'?true:false);
//define('MOD_WIN',		DIRECTORY_SEPARATOR=='\\'?true:false);

/**
 * 加载一个文件/只包含一次
 * @param string $file 见my_path()函数体
 */
function import($file)
{
	$sfile	=	my_path($file);
	if(!$sfile){
		throw new Exception("[$file] is not exists.");
	}
	
	static $included	=	array();
	if(!isset($included[$sfile]))
	{
		$included[$sfile]	=	1;
		return include($sfile);
	}
}
function my_path($file)
{
	switch(substr($file,0,2))
	{
	case '#/':	//fw根目录
		$file	=	ROOT_PATH.substr($file, 1);
		break;
	case '~/':	//项目控制器源码目录
		$file	=	Core::$APP_PATH. Core::$convent['cu_path'].substr($file, 1);
		break;
	case '$/':	//model&helper源码目录
		$file	=	SRC_PATH.substr($file, 1);
		break;
	case '%/':	//项目模板源码目录
		$file	=	View::theme()
					? TPL_PATH.'/'.View::theme().'/src'.substr($file, 1)
					: TPL_PATH.'/src'.substr($file, 1);
		break;
	default:
		return realpath($file);
	}
#	echo $file,'<br/>';
	return is_readable($file) ? $file : false;
}

import('#/core.php');
import('#/lib.php');
import('#/controller.php');

Core::prepro();

?>
